package com.rc.evcharger.service.platform;

import com.rc.evcharger.mapper.platform.PlatformSettingMapper;
import com.rc.evcharger.model.platform.PlatformSetting;
import com.rc.evcharger.model.platform.PlatformSettingExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * Created by sven on 2019/09/23.
 */
@Service
public class PlatformSettingServiceImpl implements PlatformSettingService {

    @Autowired
    private PlatformSettingMapper platformSettingMapper;

    @Override
    public PlatformSettingMapper getMapper() {
        return platformSettingMapper;
    }

    //@Override
    //public BigDecimal selectParaName(String paraName) {
    //    PlatformSetting platformSetting = platformSettingMapper.selectParaName(paraName);
    //    if (platformSetting == null || platformSetting.getParaValue() == null) {
    //        return BigDecimal.ONE;
    //    }
    //
    //    return new BigDecimal(platformSetting.getParaValue());
    //}

    @Override
    public PlatformSetting selectSettingByParaName(String paraName) {
        PlatformSettingExample example = new PlatformSettingExample();
        example.createCriteria().andParaNameEqualTo(paraName);
        List<PlatformSetting> list = platformSettingMapper.selectByExample(example);
        if (!CollectionUtils.isEmpty(list)) {
            return list.get(0);
        }

        return null;
    }
}
